#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <wait.h>
int num;
int main() {
    pid_t pid,pid1;

    /*fork a child process*/
    pid=fork();

    if(pid<0){/* error occurred */
        fprintf(stderr,"Fork Failed");
        return 1;
    }
    else if(pid==0){ /* child process */
        pid1=getpid();
        printf("child: pid= %d\n",pid);
        printf("child: pid1= %d\n",pid1);
        num++;
        printf("child: num= %d\n",num);
        printf("child: the address of num is %p\n",&num);
    }
    else{/* parent process */
        pid1=getpid();
        printf("parent: pid= %d\n",pid);
        printf("parent: pid1= %d\n",pid1);
        num--;
        printf("parent: num= %d\n",num);
        printf("parent: the address of num is %p\n",&num);
        wait(NULL);
    }
    return 0;
}
